package com.android.flowoflife;

import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.util.Log;

public class Alarms {
	static void scheduleNextPhotoshoot(Context context){
		// here must load preference value for next shooting
		scheduleNextShoot(context, 30);
	}

	static void scheduleNextShoot(Context context, int inSeconds) {
		long atTime = System.currentTimeMillis() + inSeconds * 1000l;
		PendingIntent pi = createPendingIndent(context);
		AlarmManager alarmManager = (AlarmManager)context.getSystemService(Context.ALARM_SERVICE);
		alarmManager.set(AlarmManager.RTC_WAKEUP, atTime, pi);
		Log.d(IFlowOfLifeConstants.LOG_TAG, "Next scheduled shoot will be at " + inSeconds + " seconds.");
	}

	static PendingIntent createPendingIndent(Context context) {
		Intent serviceIntent = new Intent(context, PhotoService.class);
		serviceIntent.putExtra(IFlowOfLifeConstants.STOP_SERVICE, false);
		return PendingIntent.getService(context, 0, serviceIntent, 0);
	}
	
	static void cancel(Context context){
		AlarmManager alarmManager = (AlarmManager)context.getSystemService(Context.ALARM_SERVICE);
		alarmManager.cancel(createPendingIndent(context));
	}
}
